var fs = require("fs");
const iconv =  require("iconv-lite");

fs.readFile("./C/clone/animal/gbsnake.c", function(error, data) {
    data = iconv.decode(data,'gbk');
    let j = '{'
    // j += data.replace(/([\s\S]*)inherit([\s\S]*)/, '111')
    // j += `"inherit":"${(data.match(/inherit \w+/)[0].split(' ')[1]).toLowerCase()}",
    //     ${set_name}
    // `
    j+='}'
    console.log(j)
    // let a = data.match(/\"\S\"/)
    let a = data.match(/\"[ -~]\"/)
    console.log(a[0])
    console.log(a[0].split(' ')[1])
})

/*
walkSync('C/clone', function(filePath, stat) {
    // do something with "filePath"...
    console.log(filePath)
    fs.writeFile('dev-tool/build/getfile.txt', filePath+'\r\n', {flag: 'a'}, function(err) {
        if (err) {
            throw err;
        }
    });
});
*/

// sync version
function walkSync(currentDirPath, callback) {
    var fs = require('fs'),
        path = require('path');
    fs.readdirSync(currentDirPath).forEach(function (name) {
        var filePath = path.join(currentDirPath, name);
        var stat = fs.statSync(filePath);
        if (stat.isFile()) {
            callback(filePath, stat);
        } else if (stat.isDirectory()) {
            walkSync(filePath, callback);
        }
    });
}
